<?php

class Default_GuestbookEntriesAction extends ProjectBaseAction
{
	 public function execute(AgaviRequestDataHolder $rd)
	 {
	 	$elementsPerPage = 5;
		$page = $rd->getParameter('page', 0);
		$offset = $elementsPerPage*$page; 		      
		        
		$c = new Criteria();
		$maxElements = AfgOMCommentPeer::doCount($c);
		
		$maxPages = ceil($maxElements/$elementsPerPage);
		$this->setAttribute('maxPages',$maxPages);
		
		$c->setOffset($offset);
		$c->setLimit($elementsPerPage);
		
		$c->addDescendingOrderByColumn(AfgOMCommentPeer::CREATE_TS);
		$comments = AfgOMCommentPeer::doSelect($c);	 
	
		foreach($comments as $comment) {
			$comArray[] = $comment->toArray();
		}		
		if(isset($comArray)) {
			$this->setAttribute('comments',$comArray);
			return 'Success';	
		} else {
			$vm = $this->getContainer()->getValidationManager();
			$vm->setError('nomessages','Es gibt leider noch keine Einträge in diesem Gästebuch');
			return 'Error';	
		}	 	
	 }
}

?>